package com.emo.wowoblog.service.impl;


import com.emo.wowoblog.dao.CatalogDao;
import com.emo.wowoblog.entity.Catalog;
import com.emo.wowoblog.service.CatalogService;
import com.emo.wowoblog.view.CatalogView;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CatalogServiceImpl  implements CatalogService {
    @Resource
    private CatalogDao catalogDao;
    @Override
    public List<Catalog> getCatalogsByPid(Integer pid) {
        return catalogDao.findAllByPid(pid);
    }

    @Override
    public CatalogView initCatalogView() {

        CatalogView cv = new CatalogView();
        cv.setTopCatalogList(getCatalogsByPid(0));
        Map<String,List<Catalog>> catalogMap = new HashMap<>();
        for(Catalog c: cv.getTopCatalogList()){
            catalogMap.put(c.getCid()+"",getCatalogsByPid(c.getCid()));
        }
        cv.setCatalogMap(catalogMap);
        return cv;

    }
}
